package org.zjx.app.strategy.impl;

import org.zjx.app.action.task.*;
import org.zjx.app.action.window.DialogueAction;
import org.zjx.app.commnad.ICommand;
import org.zjx.app.commnad.impl.*;
import org.zjx.app.task.TaskManager;
import org.zjx.window.action.IAction;
import org.zjx.window.action.impl.DelayAction;
import org.zjx.window.strategy.IStrategy;
import org.zjx.window.window.IWindow;
import org.zjx.window.window.impl.GameWindow;

import java.awt.*;

public class GameStrategy implements IStrategy {
    @Override
    public IAction analyze(IWindow window) {

        ICommand iCommand = window.getState().getGameState().getCommand();
        if (iCommand == null) {
            iCommand = TaskManager.getInstance().getCommand(window.getState());
        }
        if (iCommand == null){
            window.getState().getGameState().setGatherQuest(false);
        }else if (iCommand instanceof BattleCommand) {
            window.getState().getGameState().setCommand(null);
            return new DialogueAction(window, null);
        } else if (iCommand instanceof ClaimTaskCommand) {  //接取任务
            return new ClaimTaskAction(window, ((ClaimTaskCommand) iCommand).getNpc(), ((ClaimTaskCommand) iCommand).getDialogues());
        } else if (iCommand instanceof PatrolCommand) {
                return new PatrolTaskAction(window, ((PatrolCommand) iCommand).getPoints());
        } else if (iCommand instanceof DeliverTaskCommand){
            return new DeliverTaskAction(window,((DeliverTaskCommand) iCommand).getNpc(), ((DeliverTaskCommand) iCommand).getDialogues());
        }else if (iCommand instanceof GiveNpcItemCommand){
            return new GiveNpcItemTaskAction(window,((GiveNpcItemCommand) iCommand).getNpc(),((GiveNpcItemCommand) iCommand).getSlotType(),((GiveNpcItemCommand) iCommand).getItemName());
        }else if ((iCommand instanceof BuyItemCommand)){
            return new BuyItemTaskAction(window,((BuyItemCommand) iCommand).getItemName(),((BuyItemCommand) iCommand).getQuantity());
        }

        return new DelayAction(window, 3000);
    }

    @Override
    public String getName() {
        return "游戏总策略";
    }

    @Override
    public int getPriority() {
        return 60;
    }

    @Override
    public boolean isApplicable(IWindow window) {
        return window instanceof GameWindow;
    }
}
